package com.itjeffrey.autocode.controller;

import com.itjeffrey.autocode.bo.req.MenuInfoBO;
import com.itjeffrey.autocode.common.Result;
import com.itjeffrey.autocode.service.MenuInfoService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @From: Jeffrey
 * @Date: 2021/4/17
 */
@RestController
@RequestMapping("/menu/info")
public class MenuInfoController {

    @Resource
    private MenuInfoService menuInfoService;

    /**
     * 新增菜单
     * @param menuInfoBO
     * @return
     */
    @PostMapping("/add")
    public ResponseEntity<Result> addMenu(@RequestBody MenuInfoBO menuInfoBO){
        return ResponseEntity.ok(menuInfoService.addMenu(menuInfoBO));
    }

    /**
     * 修改菜单
     * @param menuInfoBO
     * @return
     */
    @PostMapping("/mod")
    public ResponseEntity<Result> modMenu(@RequestBody MenuInfoBO menuInfoBO){
        return ResponseEntity.ok(menuInfoService.modMenu(menuInfoBO));
    }

    /**
     * 删除菜单
     * @param menuId
     * @return
     */
    @PostMapping("/delete/{id}")
    public ResponseEntity<Result> deleteMenu(@PathVariable("id") Integer menuId){
        return ResponseEntity.ok(menuInfoService.deleteMenu(menuId));
    }

    /**
     * 查询所有菜单列表
     * @param menuInfoBO
     * @return
     */
    @PostMapping("/query/list")
    public ResponseEntity<Result> queryList(@RequestBody MenuInfoBO menuInfoBO){
        return ResponseEntity.ok(menuInfoService.queryList(menuInfoBO));
    }

    /**
     * 查询所有父菜单列表
     * @param menuInfoBO
     * @return
     */
    @PostMapping("/query/plist")
    public ResponseEntity<Result> querypList(@RequestBody MenuInfoBO menuInfoBO){
        return ResponseEntity.ok(menuInfoService.querypList(menuInfoBO));
    }

    /**
     * 查询所有子菜单列表
     * @param menuInfoBO
     * @return
     */
    @PostMapping("/query/slist")
    public ResponseEntity<Result> querysList(@RequestBody MenuInfoBO menuInfoBO){
        return ResponseEntity.ok(menuInfoService.querysList(menuInfoBO));
    }

    /**
     * 获取所有菜单
     * @return
     */
    @GetMapping("/getAllMenu")
    public ResponseEntity<Result> getAllMenu(){
        return ResponseEntity.ok(menuInfoService.getAllMenu());
    }

    /**
     * 获取指定登录用户的菜单列表
     * @return
     */
    @GetMapping("/getMenuByLoginName")
    public ResponseEntity<Result> getMenuByLoginName(@RequestParam("loginName") String loginName){
        return ResponseEntity.ok(menuInfoService.getMenuByLoginName(loginName));
    }
}
